//
//  UIImage+TS.swift
//  TSKit
//
//  Created by chenyusen on 2018/3/16.
//

import UIKit


// MARK: - 初始化方法扩展
public extension UIImage {
    
    /// 创建一个指定颜色的UIImage实例
    ///
    /// - Parameters:
    ///   - color: 指定的颜色
    ///   - size: 指定的尺寸,可以不传,默认为尺寸长宽为1
    public convenience init(color: UIColor, size: CGSize? = CGSize(width: 1, height: 1)) {
        UIGraphicsBeginImageContextWithOptions(size!, false, 1)
        color.setFill()
        UIRectFill(CGRect(x: 0, y: 0, width: size!.width, height: size!.height))
        guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
            self.init()
            return
        }
        UIGraphicsEndImageContext()
        guard let aCgImage = image.cgImage else {
            self.init()
            return
        }
        self.init(cgImage: aCgImage)
    }
}


// MARK: - 属性扩展
public extension UIImage {
    
    public var original: UIImage {
        return withRenderingMode(.alwaysOriginal)
    }
    
    public var template: UIImage {
        return withRenderingMode(.alwaysTemplate)
    }
}


